﻿@{
    ViewBag.Title = "Чекери";
    const string ControllerName = "Checkers";
}
<h1>@ViewBag.Title</h1>

@(Html.Kendo().Grid<OJS.Web.Areas.Administration.ViewModels.Checker.CheckerAdministrationViewModel>()
    .Name("DataGrid")
    .Columns(columns =>
        {
            columns.Bound(col => col.Id);
            columns.Bound(col => col.Name);
            columns.Bound(col => col.Description).Hidden();
            columns.Bound(col => col.DllFile);
            columns.Bound(col => col.ClassName);
            columns.Bound(col => col.Parameter).ClientTemplate("#= substring(Parameter) #");
            columns.Bound(col => col.CreatedOn).Format("{0:dd/MM/yyyy HH:mm}").Hidden();
            columns.Bound(col => col.ModifiedOn).Format("{0:dd/MM/yyyy HH:mm}").Hidden();
            columns.Command(command => command.Edit().Text(" ").UpdateText("Промяна").CancelText("Отказ")).Width(80);
            columns.Command(command => command.Destroy().Text(" ")).Width(80);
        })
    .ToolBar(toolbar =>
    {
        toolbar.Create().Text("Създай");
        toolbar.Custom().Text("Обратно към администрацията").Action("Navigation", "Administration", new { Area = "" }).Name("custom-toolbar-button");
        toolbar.Custom().Text("Експорт към Excel").Name("custom-toolbar-button").HtmlAttributes(new { id = "export" }).Url(Url.Action("ExportToExcel", ControllerName, new { page = 1, pageSize = "~", filter = "!!", sort = "~" }));
    })
    .Editable(editable =>
    {
        editable.Mode(GridEditMode.PopUp);
        editable.Window(w => w.Title(ViewBag.Title));
        editable.DisplayDeleteConfirmation("Наистина ли искате да изтриете елемента?");
    })
    .ColumnMenu()
    .Events(e => e.DataBound("onDataBound"))
    .Pageable(x => x.Refresh(true))
    .Sortable(x => x.Enabled(true).AllowUnsort(false))
    .Filterable(x => x.Enabled(true))
        /*.Groupable(x =>
        {
            x.Enabled(true);
            x.Messages(m => m.Empty("Хванете заглавието на колона и го преместете тук, за да групирате по тази колона."));
        })*/
    .Reorderable(x => x.Columns(true))
    .Resizable(x => x.Columns(true))
    .DataSource(datasource => datasource
        .Ajax()
        .ServerOperation(true)
        .Model(model =>
            {
                model.Id(m => m.Id);
                model.Field(m => m.DllFile).DefaultValue("OJS.Workers.Checkers.dll");
                model.Field(m => m.ClassName).DefaultValue("OJS.Workers.Checkers.CSharpCodeChecker");
            })
        .Sort(sort => sort.Add(x => x.CreatedOn).Descending())
        .Create(create => create.Action("Create", ControllerName))
        .Read(read => read.Action("Read", ControllerName))
        .Update(update => update.Action("Update", ControllerName))
        .Destroy(destroy => destroy.Action("Destroy", ControllerName))
        .Events(ev => ev.Error("validateModelStateErrors"))
    )
)

<script type="text/javascript">
    function onDataBound(e) {
        CreateExportToExcelButton();
    }

    function substring(value) {
        if (value == null || value == undefined || value == "") {
            return "";
        }
        else {
            return value.toString().length > 100 ? value.substring(0, 100) + "..." : value;
        }
    }
</script>